import { AnimationClip } from 'cc';
import State from '../../Base/State';
import { StateMachine } from '../../Base/StateMachine';
import { SubStateMachine } from '../../Base/SubStateMachine';
import { DIRECTION_ENUM, DIRECTION_ORDER_ENUM, PARAMS_NAME_ENUM } from '../../Enums';

const BASE_URL = 'texture/woodenskeleton/idle/'

export default class IdleSubStateMachine extends SubStateMachine {
  constructor(fsm:StateMachine) {
    super(fsm)
    this.states.set(DIRECTION_ENUM.TOP, new State(fsm,`${BASE_URL}top`, AnimationClip.WrapMode.Loop))
    this.states.set(DIRECTION_ENUM.BOTTOM, new State(fsm,`${BASE_URL}bottom`, AnimationClip.WrapMode.Loop))
    this.states.set(DIRECTION_ENUM.LEFT, new State(fsm,`${BASE_URL}left`, AnimationClip.WrapMode.Loop))
    this.states.set(DIRECTION_ENUM.RIGHT, new State(fsm,`${BASE_URL}right`, AnimationClip.WrapMode.Loop))

  }

  run() {
    // 子状态机公用父状态机的 params
    const value = this.fsm.getParams(PARAMS_NAME_ENUM.DIRECTION)
    // 在 Map 找到 DIRECTION_ENUM.TOP的 State 对象赋值给 currentState（赋值的时候，就会 run 这个 State 实例）
    this.currentState = this.states.get(DIRECTION_ORDER_ENUM[value as number])
  }
}
